//
// Created by Administrator on 2021/11/9.
// May Saint Diana bless you!
//
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <climits>

using namespace std;

class Solution {
public:
    vector<bool> checkArithmeticSubarrays(vector<int> &nums, vector<int> &l, vector<int> &r) {
        // 暴力？
        vector<bool> ans(l.size(), false);
        for (int i = 0; i < l.size(); ++i) {
            ans[i] = isArithmetic(vector<int>(nums.begin() + l[i], nums.begin() + r[i] + 1));
        }
        return ans;
    }

    /**
     * 判断数组是否可以重排成等差
     * @param nums
     * @return
     */
    bool isArithmetic(vector<int> nums) {
        sort(nums.begin(), nums.end());
        int diff = nums[1] - nums[0];
        for (int i = 0; i < nums.size() - 1; ++i) {
            if (nums[i + 1] - nums[i] != diff)
                return false;
        }
        return true;
    }
};

int main() {
    vector<int> nums{4, 6, 5, 9, 3, 7};
    vector<int> l{0, 0, 2};
    vector<int> r{2, 3, 5};
    Solution solution;
    vector<bool> ans = solution.checkArithmeticSubarrays(nums, l, r);
    for (const auto &x: ans) cout << x << endl;
    return 0;
}
